<include file='Common:header'/>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            系统设置
            <small></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="{:U('Index/index')}"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">系统设置</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <form role="form" method="post">
            <!-- START CUSTOM TABS -->
            <div class="row">
                <div class="col-xs-12">
                    <!-- Custom Tabs -->
                    <div class="nav-tabs-custom">

                        <ul class="nav nav-tabs">

                            <!--
                            <li class="active"><a href="#tab_1" data-toggle="tab">站点配置</a></li>
                            <li><a href="#tab_2" data-toggle="tab">上传配置</a></li>
                            <li><a href="#tab_3" data-toggle="tab">性能优化</a></li>
                            -->

                            <volist name="data" id="d">
                                <li <if condition="$i eq 1">class="active"</if>>
                                <a href="#tab_{$d.cgname}" data-toggle="tab" rel="tab_{$d.cgname}">{$d.cgtitle}</a>
                                </li>
                            </volist>
                            <li><a href="javascript:void(0)" onclick="addCfg()">添加配置</a></li>

                            <li class="pull-right"><a href="javascript:void(0)" onclick="addCfg()" class="text-muted"><i class="fa fa-gear"></i></a></li>
                        </ul>

                        <div class="tab-content">

                            <volist name="data" id="d" key="k">
                                <div class="tab-pane <if condition="$k eq 1">active</if>" id="tab_{$d.cgname}">
                                <div style="width:100%;">
                                    <div class="box">
                                        <div class="box-header with-border">
                                            <h3 class="box-title">{$d.cgtitle}</h3>
                                        </div><!-- /.box-header -->
                                        <div class="box-body">

                                            <table class="table table-bordered">
                                                <tbody><tr>
                                                    <th style="width: 50px">排序</th>
                                                    <th style="width: 180px">标题</th>
                                                    <th style="width: 350px">配置值</th>
                                                    <th style="width: 300px">变量</th>
                                                    <th>描述</th>
                                                </tr>
                                                <volist name="d[_config]" id="c">
                                                    <tr>
                                                        <td>
                                                            <input type="text" name="config[{$c.id}][order_list]" value="{$c.order_list}" class="took-w40"/>
                                                            <input type="hidden" name="config[{$c.id}][id]" value="{$c['id']}"/>
                                                        </td>
                                                        <td>{$c.title}
                                                            <if condition="$c[system] eq 0">
                                                                <a href="javascript:del({$c.id})">删除</a>
                                                            </if>
                                                        </td>
                                                        <td>{$c._html}</td>
                                                        <td>{$c.name}</td>
                                                        <td>{$c.message}</td>
                                                    </tr>
                                                </volist>
                                                </tbody></table>
                                        </div><!-- /.box-body -->
                                    </div><!-- /.box -->
                                </div>
                        </div><!-- /.tab-pane -->
                        </volist>

                        <button class="btn btn-info btn-lg" style="width:100px; display:block;" type="submit">保存</button>

                    </div><!-- /.tab-content -->

                </div><!-- nav-tabs-custom -->
            </div><!-- /.col -->

</div> <!-- /.row -->
<!-- END CUSTOM TABS -->
</form>

</section><!-- /.content -->
</div><!-- /.content-wrapper -->


<!-- 模态框（Modal） -->
<div class="modal fade" id="addCfgModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close"
                        data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    添加配置
                </h4>
            </div>
            <div class="modal-body">

                <form role="form" method="post" action="{:U('add')}">
                    <div class="col-md-6">
                        <!-- general form elements -->
                        <div class="box box-primary">
                            <div class="box-body">
                                <div class="form-group">
                                    <label for="title">标题（中文）</label>
                                    <input type="text" placeholder="" id="title" name="title" class="form-control">
                                </div>
                                <div class="form-group">
                                    <label for="name">变量名（英文）</label>
                                    <input type="text" placeholder="" id="name" name="name" class="form-control">
                                </div>
                                <div class="form-group">
                                    <label for="message">提示信息</label>
                                    <textarea placeholder="" rows="3" id="message" name="message" class="form-control"></textarea>
                                </div>
                                <div class="form-group">
                                    <label for="cgid">配置组</label>
                                    <select id="cgid" name="cgid" class="form-control">
                                        <volist name="configGroup" id="g">
                                            <option value="{$g.cgid}">{$g.cgtitle}</option>
                                        </volist>
                                    </select>
                                </div>
                            </div><!-- /.box-body -->
                        </div><!-- /.box -->
                    </div>
                    <!-- /.col-md -->

                    <div class="col-md-6">
                        <!-- general form elements -->
                        <div class="box box-primary">
                            <div class="box-body">
                                <div class="form-group">
                                    <label>显示方法</label>
                                    <div class="radio">
                                        <label>
                                            <input type="radio" value="text" id="optionsRadios1" name="show_type" checked="">
                                            text
                                        </label>
                                    </div>
                                    <div class="radio">
                                        <label>
                                            <input type="radio" value="radio" id="optionsRadios2" name="show_type">
                                            radio
                                        </label>
                                    </div>
                                    <div class="radio">
                                        <label>
                                            <input type="radio" value="textarea" id="optionsRadios3" name="show_type">
                                            textarea
                                        </label>
                                    </div>
                                    <div class="radio">
                                        <label>
                                            <input type="radio" value="select" id="optionsRadios4" name="show_type">
                                            select
                                        </label>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="value">配置值</label>
                                    <input type="text" placeholder="" id="value" name="value" class="form-control">
                                </div>
                                <div class="form-group">
                                    <label for="value">参数（对radio与select有效)</label>
                                    <textarea placeholder="" rows="3" id="info" name="info" class="form-control"></textarea>
                                    如：1|开启,0|关闭
                                </div>
                            </div><!-- /.box-body -->
                        </div><!-- /.box -->
                    </div>
                    <!-- /.col-md -->

                    <div class="box-footer">
                        <button class="btn btn-primary" type="submit">添加</button>
                    </div>
                </form>

            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<script>
    //添加配置表单
    function addCfg() {
        $('#addCfgModal').modal();
    }

    //删除配置
    function del(id) {
        delItem('{:U('del')}', {id: id});
    }

    $(function() {
        $('#tab_email table').after('<div class="input-group input-group-sm" style="width:350px; margin:10px 0"><input type="email" placeholder="输入邮箱" class="form-control" id="mail_to"><span class="input-group-btn"><button type="button" class="btn btn-info btn-flat" id="btn_testmail" onclick="test_mail()">测试发送</button></span></div>');
    });

    function test_mail() {
        var uri = "{:U('ajaxmail')}"+"&t="+(new Date()).getTime();
        $.post(uri,{
                    mail_to:$('#mail_to').val(),
                    mail_host:$('#MAIL_HOST').val(),
                    mail_port:$('#MAIL_PORT').val(),
                    mail_user:$('#MAIL_USER').val(),
                    mail_pwd:$('#MAIL_PWD').val(),
                    mail_from:$('#MAIL_FROM').val(),
                    mail_fname:$('#MAIL_FNAME').val(),
                },
                function(d){
                    if(d.status) {
                        MsgBox.success( "测试邮件发送成功！" );
                    }
                    else {
                        MsgBox.error(d.info);
                    }
                });
    }
</script>

<include file='Common:footer'/>
